﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SDMX_Common = SDMX_ML.Framework.Common;

namespace SDMX_ML.Framework.Structure
{
    class HierarchicalCodelistType
    {
        private List<SDMX_Common.TextType> _name;
        private List<SDMX_Common.TextType> _description;
        private List<CodelistRefType> _codelistRef;
        private List<HierarchyType> _hierarchy;
        private SDMX_Common.AnnotationsType _annotations;
        private SDMX_Common.IDType _id;
        private SDMX_Common.IDType _agencyID;
        private string _version;
        private string _urn;
        private string _uri;
        private bool? _isExternalReference;
        private bool? _isFinal;
        private string _validFrom;
        private string _validTo;

        /// <summary>
        /// HierarchyType.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        public HierarchicalCodelistType(SDMX_Common.TextType name, SDMX_Common.IDType id, SDMX_Common.IDType agencyID)
        {
            if (name != null & id != null)
            {
                if (!String.IsNullOrEmpty(name.Text))
                {
                    _name = new List<SDMX_Common.TextType>();
                    _description = new List<SDMX_Common.TextType>();
                    _codelistRef = new List<CodelistRefType>();
                    _hierarchy = new List<HierarchyType>();

                    _name.Add(name);
                }
                else
                {
                    throw new Exception("Text in element name is missing.");
                }

                if (!String.IsNullOrEmpty(id.Value))
                {
                    _id = id;
                }
                else
                {
                    throw new Exception("Value in attribute id is missing.");
                }

                if (!String.IsNullOrEmpty(agencyID.Value))
                {
                    _agencyID = agencyID;
                }
                else
                {
                    throw new Exception("Value in attribute agencyID is missing.");
                }

            }
            else
            {
                throw new Exception("Element Name and attribute id are required in HierarchyType.");
            }
        }

        //Elements

        /// <summary>
        /// Name.
        /// </summary>
        public List<SDMX_Common.TextType> Name
        {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Hierarchy.
        /// </summary>
        public List<HierarchyType> Hierarchy
        {
            get { return _hierarchy; }
            set { _hierarchy = value; }
        }
 
        /// <summary>
        /// Description.
        /// </summary>
        public List<SDMX_Common.TextType> Description
        {
            get { return _description; }
            set { _description = value; }
        }
 
        /// <summary>
        /// CodelistRef.
        /// </summary>
        public List<CodelistRefType> CodelistRef
        {
            get { return _codelistRef; }
            set { _codelistRef = value; }
        }
  
         /// <summary>
        /// Annotations.
        /// </summary>
        public SDMX_Common.AnnotationsType Annotations
        {
            get { return _annotations; }
            set { _annotations = value; }
        }

        //Attributes
         public SDMX_Common.IDType Id
        {
            get { return _id; }
            set { _id = value; }
        }

        /// <summary>
        /// AgencyID.
        /// </summary>
         public SDMX_Common.IDType AgencyID
         {
             get { return _agencyID;}
             set { _agencyID = value; }
         }
        
        /// <summary>
        /// Urn.
        /// </summary>
        public string Urn
        {
            get { return _urn; }
            set { _urn = value; }
        }

        /// <summary>
        /// Uri.
        /// </summary>
        public string Uri
        {
            get { return _uri; }
            set { _uri = value; }
        }
        
        /// <summary>
        /// Version.
        /// </summary>
        public string Version
        {
            get { return _version; }
            set { _version = value; }
        }
 
        /// <summary>
        /// IsFinal.
        /// </summary>
        public bool? IsFinal
        {
            get { return _isFinal; }
            set { _isFinal = value; }
        }

        /// <summary>
        /// IsFinal.
        /// </summary>
        public bool? IsExternalReference
        {
            get { return _isExternalReference; }
            set { _isExternalReference = value; }
        }
        

        /// <summary>
        /// ValidFrom.
        /// </summary>
        public string ValidFrom
        {
            get { return _validFrom; }
            set { _validFrom = value; }
        }

        /// <summary>
        /// ValidTo.
        /// </summary>
        public string ValidTo
        {
            get { return _validTo; }
            set { _validTo = value; }
        }
    }
}
